package config

import (
	"net/http"
)

// contextKeys are used to identify the type of value in the context.
// Since these are string, it is possible to get a short description of the
// context key for logging and debugging using key.String().

type contextKey string

func (c contextKey) String() string {
	return "ck " + string(c)
}

var (
	PId              = contextKey("pid")
	Secret           = contextKey("secret")
	ContextEnableLog = contextKey("enable_log")
)

// Configuration stores the configuration of the API client
type Configuration struct {
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	LogEnable     bool              `json:"log_enable,omitempty"`
	HTTPClient    *http.Client
}

func NewConfiguration() *Configuration {
	cfg := &Configuration{
		DefaultHeader: make(map[string]string),
		Host:          "par.zhangwenpindu.cn",
		Scheme:        "https",
		LogEnable:     false,
	}
	return cfg
}

func (c *Configuration) AddDefaultHeader(key string, value string) {
	c.DefaultHeader[key] = value
}

func (c *Configuration) GetBasePath() string {
	return c.Scheme + "://" + c.Host
}
